/**
 * Copyright 2007 MartiniMix.net
 */
package net.martinimix.logging;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogConfigurationException;
import org.apache.commons.logging.LogFactory;

/**
 * Provides a Blue Martini log factory for Apache Common's Logging.
 * 
 * @author Scott Rossillo
 *
 */
public class BlueMartiniLogFactory extends LogFactory {
	
	protected final static boolean DEBUG_INTERNAL_ENABLED = 
		Boolean.getBoolean("net.martinimix.logging.debug");
	
	private final Map attributes = new HashMap();
	
	/**
	 * Constructs a new Blue Martini logging factory.
	 */
	public BlueMartiniLogFactory() {
		super();
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#getAttribute(java.lang.String)
	 */
	public Object getAttribute(String key) {
		
		return attributes.get(key);
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#getAttributeNames()
	 */
	public String[] getAttributeNames() {
		
		return (String[]) attributes.keySet().toArray(new String [0]);
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#getInstance(java.lang.Class)
	 */
	public Log getInstance(Class clazz) throws LogConfigurationException {
		
		return this.getInstance(clazz.getName());
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#getInstance(java.lang.String)
	 */
	public Log getInstance(String clazz) throws LogConfigurationException {
		
		BlueMartiniLog log =  new BlueMartiniLog(clazz);
		log.setLogFactory(this);
		
		return log;
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#release()
	 */
	public void release() {
		/* not needed */
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#removeAttribute(java.lang.String)
	 */
	public void removeAttribute(String key) {

		attributes.remove(key);
	}

	/* (non-Javadoc)
	 * @see org.apache.commons.logging.LogFactory#setAttribute(java.lang.String, java.lang.Object)
	 */
	public void setAttribute(String key, Object value) {
		
		attributes.put(key, value);
	}

}
